home *** CD-ROM | disk | FTP | other *** search
- global datemode, dayOffset, day1, sMode, smallnil
-
- on dateInit
- set datemode to [#month: 1, #day: 2, #year: 3]
- set dayOffset to 0
- end
-
- on date
- legalMode()
- set x to the result
- set day to the day of x + dayOffset
- set month to the month of x
- set year to the year of x
- lastday(month, year)
- if day > the result then
- set day to 1
- set year to (100 + year + (month = 12)) mod 100
- set month to (month mod 12) + 1
- end if
- if day < 1 then
- set year to (100 + year - (month = 1)) mod 100
- set month to ((month + 10) mod 12) + 1
- lastday(month, year)
- set day to the result
- end if
- dateDisplay(month, day, year)
- end
-
- on dateDisplay month, day, year
- DayOfWeek(month, day, year)
- set dcast to the result + day1 - 1
- set the castNum of sprite sMode to dcast
- set x to the month of datemode < the day of datemode
- donum(14 - (3 * x), smallnil, 1, month)
- donum(11 + (3 * x), smallnil, 1, day)
- set the castNum of sprite (20 - x) to the number of cast "month"
- set the castNum of sprite (19 + x) to the number of cast "unmonth"
- end
-
- on legalMode
- extractDate()
- set date to the result
- set legal to 0
- repeat while not legal
- set day to getAt(date, the day of datemode)
- set month to getAt(date, the month of datemode)
- set year to getAt(date, the year of datemode)
- if (month <= 12) and (month >= 1) then
- lastday(month, year)
- if (day <= the result) and (day >= 1) then
- set legal to 1
- end if
- end if
- if not legal then
- nextmode()
- end if
- end repeat
- return [#day: day, #month: month, #year: year]
- end
-
- on extractDate
- set date to the date
- set del1 to 0
- set del2 to 0
- set len to the length of date
- repeat with x = 1 to len
- if not integerp(integer(char x of date)) or (char x of date = "-") then
- if not del1 then
- set del1 to x
- next repeat
- end if
- set del2 to x
- end if
- end repeat
- set d1 to integer(chars(date, 1, del1 - 1))
- set d2 to integer(chars(date, del1 + 1, del2 - 1))
- set d3 to integer(chars(date, del2 + 1, len))
- return [d1, d2, d3]
- end
-
- on DayOfWeek month, day, year
- if year > 100 then
- set cent to year / 100
- set year to year mod 100
- else
- set cent to 19 + (year < 95)
- set year to (100 + year) mod 100
- end if
- set val to (year / 4) + day + getAt([1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6], month)
- if not (year mod 4) and (month <= 2) then
- set val to val - 1
- end if
- if cent = 20 then
- set val to val + 6
- end if
- set val to val + year
- set val to val mod 7
- return 1 + ((7 + val - 1) mod 7)
- end
-
- on lastday month, year
- set feb to 28 + not (year mod 4)
- return getAt([31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], month)
- end
-
- on nextmode
- set m to the month of datemode
- set d to the day of datemode
- set y to the year of datemode
- set switch to (y = (d + 2)) - (y = (m - 2))
- set the month of datemode to d + switch
- set the day of datemode to m + switch
- if switch then
- set the year of datemode to y - (2 * switch)
- end if
- end
-